package com.deng.template.web.exception;

import com.alibaba.fastjson.JSON;
import com.deng.template.common.model.CnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author deng
 * @Date 2022/1/11 15:38
 */
@RestControllerAdvice
@Slf4j
@RequestMapping(produces = "application/json;charset=UTF-8")
public class HandlerException {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public String Exception(Exception e){
        e.printStackTrace();
        log.error("HandlerException e is {}", e.getMessage());
        return JSON.toJSONString(new CnResult<Void>(false, e.getMessage(), null));
    }
}
